package me.zhengjie.modules.houseshowscene.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.houseshowscene.domain.HouseShowScene;
import me.zhengjie.modules.houseshowscene.service.HouseShowSceneService;
import me.zhengjie.modules.houseshowscene.service.dto.HouseShowSceneDto;
import me.zhengjie.modules.houseshowscene.service.dto.HouseShowSceneQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author TianI
* @date 2021-12-24
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "HouseShowConfigController管理")
@RequestMapping("/api/houseShowScene")
public class HouseShowSceneController {

    private final HouseShowSceneService houseShowSceneService;

    @GetMapping
    @Log("查询HouseShowConfigController")
    @ApiOperation("查询HouseShowConfigController")
    @PreAuthorize("@el.check('houseShowScene:list')")
    public ResponseEntity query(HouseShowSceneQueryParam query, Pageable pageable){
        return new ResponseEntity<>(houseShowSceneService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增HouseShowConfigController")
    @ApiOperation("新增HouseShowConfigController")
    @PreAuthorize("@el.check('houseShowScene:add')")
    public ResponseEntity create(@Validated @RequestBody HouseShowSceneDto resources){
        return new ResponseEntity<>(houseShowSceneService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改HouseShowConfigController")
    @ApiOperation("修改HouseShowConfigController")
    @PreAuthorize("@el.check('houseShowScene:edit')")
    public ResponseEntity update(@Validated @RequestBody HouseShowSceneDto resources){
        houseShowSceneService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除HouseShowConfigController")
    @ApiOperation("删除HouseShowConfigController")
    @PreAuthorize("@el.check('houseShowScene:del')")
    public ResponseEntity delete(@RequestBody Set<Long> ids) {
        houseShowSceneService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出HouseShowConfigController")
    @ApiOperation("导出HouseShowConfigController")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('houseShowScene:list')")
    public void download(HttpServletResponse response, HouseShowSceneQueryParam query) throws IOException {
        houseShowSceneService.download(houseShowSceneService.queryAll(query), response);
    }*/

}
